package com.goldfish666.esp8266;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class SendTest {

    private static String powerSwitchOn = "2 1 0 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0";

    private static byte[] buff = new byte[121];

    private static void setBuff() {
        List<Byte> list = Arrays.stream(powerSwitchOn.split(" ")).map(x -> (byte) Integer.parseInt(x)).collect(Collectors.toList());
        for (int i = 0; i < buff.length; i++) {
            buff[i] = list.get(i);
        }
    }

    public static void main(String[] args) throws Exception {

        setBuff();

        DatagramSocket socket = new DatagramSocket();
//        byte[] buf = "ge men lai le".getBytes();
        //将数据打包
        DatagramPacket packet = new DatagramPacket(buff, buff.length, InetAddress.getByName("192.168.0.100"), 8090);
        socket.send(packet);
        socket.close();

    }
}
